using System;
using System.Data.SqlClient;
using System.Data;
using Net.BugOnline.Common;
using Microsoft.ApplicationBlocks.Data;


namespace Net.BugOnline.DataAccess
{

	/// <summary>
	/// Data Access Base Class
	/// </summary>
	public class DA_Base
	{
		static	SqlConnection sqlConn;

		static DA_Base()
		{
            sqlConn = new SqlConnection(Config.Instance.DatabaseConnectionString);
		}

		/// <summary>
		/// Run a sql,return a dataset
		/// </summary>
		/// <param name="cmdText"></param>
		/// <returns></returns>
		public static DataSet RunReturnDS(string cmdText)
		{
			return SqlHelper.ExecuteDataset(sqlConn,CommandType.Text,cmdText);
		}

		/// <summary>
		/// run a sql, return a dataset
		/// </summary>
		/// <param name="cmdText"></param>
		/// <param name="commandParameters"></param>
		/// <returns></returns>
		public static DataSet RunReturnDS(string cmdText,params SqlParameter[] commandParameters)
		{
			return SqlHelper.ExecuteDataset(sqlConn, CommandType.Text, cmdText, commandParameters);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cmdText"></param>
		/// <param name="commandParameters"></param>
		/// <returns></returns>
		public static int ExecuteNonQuery(string cmdText, params SqlParameter[] commandParameters)
		{
			return SqlHelper.ExecuteNonQuery(sqlConn, CommandType.Text, cmdText, commandParameters);

		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cmdText"></param>
		/// <returns></returns>
		public static int ExecuteNonQuery(string cmdText)
		{
			return SqlHelper.ExecuteNonQuery(sqlConn,CommandType.Text,cmdText);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cmdText"></param>
		/// <returns></returns>
		public static object  ExecuteScalar(string cmdText)
		{
			return SqlHelper.ExecuteScalar(sqlConn,CommandType.Text,cmdText);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cmdText"></param>
		/// <param name="commandParameters"></param>
		/// <returns></returns>
		public static object  ExecuteScalar(string cmdText, params SqlParameter[] commandParameters)
		{
			return SqlHelper.ExecuteScalar(sqlConn, CommandType.Text, cmdText, commandParameters);
		}
	}
}
